/**
 * 成绩类
 * 选择是比赛->选择初赛或预赛或者决赛->查看比赛作品成绩
 *
 * 任务一
 * 根据比赛步骤的guid获取比赛作品成绩列表(引用图:比赛作品成绩详细)
 * 步骤:
 * 1. 根据比赛步骤获取作品列表(处理有没有)
 * 2. 根据作品guid查询作品基本信息和成绩(各评委的成绩和总成绩(计算))
 */

const GradeListClass = require('../../tools/getStepGradeList');
const BaseRest = require('../rest.js');
module.exports = class extends BaseRest
{

    constructor(ctx)
    {
        super(ctx);
        this._cpstepToWorkModel = this.model('apiv1/competitionsteptoworks');
        this.judgerModel = this.model('apiv1/judger');
    }

    async getAction()
    {


        if (this._guid)
        {
            //获取比赛作品信息
            let competitionStepData = await  this.model('apiv1/competitionSteps').setRelation(true).find(this._guid);
            if (think.isEmpty(competitionStepData)) return this.responseEmpty();
            let worksData = await this._cpstepToWorkModel.getWorksByStepGuid(this._guid);
            //成绩
            let gradeList = (new GradeListClass(competitionStepData, worksData)).list();
            // let judgerIds = gradeList.shift();
            //裁判
            if (think.isEmpty(gradeList['judgers'])) return this.responseEmpty();
            gradeList['judgers'] = await this.judgerModel.setRelation(false).where(
                {
                    PK_JudgerGuid: ['in', gradeList['judgers']]
                }
            ).select();
            if (think.isEmpty(gradeList)) return this.end();
            return this.responseQuery(gradeList);
        }
        return this.end();
    }


    //测试接口 无效
    async judgerAction()
    {

        this.model('apiv1/competitionSteps').getGradeAndJudgerByStepGuid(this._guid);

    }
};